var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (e, a) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, e) {
              t.__proto__ = e;
            }) ||
          function (t, e) {
            for (var a in e)
              Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
          })(e, a);
      };
      return function (e, a) {
        function i() {
          this.constructor = e;
        }
        if ("function" != typeof a && null !== a)
          throw new TypeError(
            "Class extends value " + String(a) + " is not a constructor or null"
          );
        t(e, a),
          (e.prototype =
            null === a
              ? Object.create(a)
              : ((i.prototype = a.prototype), new i()));
      };
    })(),
  PrivateChatDialog = (function (t) {
    function e() {
      var e = t.call(this) || this;
      return (
        (e.messageArray = []),
        (e.chatMsgTotalHeigh = 0),
        (e.chatface = ChatFaceView.showChatFaceView()),
        (e.onLoadChatMsgDataFn = {
          caller: e,
          code: 1023,
          method: function (t) {
            if (0 == t.code) {
              var a = new Date(),
                i =
                  a.getFullYear() +
                  ":" +
                  (a.getMonth() + 1) +
                  ":" +
                  a.getDay() +
                  " " +
                  a.getHours() +
                  ":" +
                  a.getMinutes(),
                o = { content: e.currentMsg, date: i, fname: "我" },
                s = new ChatLineView();
              s.privateChatLineMessage(o),
                e.messageArray.unshift(s),
                e.updateMessageViewRender();
            } else ToastView.toastView(t.msg);
          },
        }),
        e.btn_send_chat.on(Laya.Event.CLICK, e, e.onClickSendMessageFn),
        e.btn_chatMsg_close.on(Laya.Event.CLICK, e, e.onChatMsgCancleFn),
        WebSocketService.addListener(e.onLoadChatMsgDataFn, !0),
        WebSocketService.addListener({
          caller: e,
          code: 1033,
          method: e.receiveMessage,
        }),
        (e.closeHandler = new Laya.Handler(e, e.onCloseChatMsgFns)),
        e.btn_image_emoji.on(Laya.Event.CLICK, e, e.onSelectedFaceEmojiAction),
        Laya.stage.on("faceType_private_chat", e, e.onGetFaceEmojiType),
        e
      );
    }
    return (
      __extends(e, t),
      (e.showPrivateMsgDialog = function (t) {
        null == this.chatMsgDialog &&
          ((this.chatMsgDialog = new e()), (this.chatMsgDialog.zOrder = 1e3)),
          this.chatMsgDialog.popup(!0),
          (this.chatState = !0),
          (this.chatMsgDialog.label_private_title.text = t.name),
          (this.chatMsgDialog.chatMsgTotalHeigh = 0),
          (this.chatMsgDialog.jsonDict = t),
          WebSocketService.send({ c: 1033, d: { roleid: t.id } });
      }),
      (e.prototype.receiveMessage = function (t) {
        if (null != t.list) {
          for (var e = [], a = "", i = [], o = 0; o < t.list.length; o++) {
            var s = t.list[o];
            if (s && s.date) {
              (a = s.date),
                this.isDuringDate(a)
                  ? localStorage.setItem("msg_" + a, JSON.stringify(s))
                  : localStorage.removeItem("msg_" + a);
              var n = localStorage.getItem("msg_" + a);
              e.push(JSON.parse(n));
            }
          }
          (i = e),
            this.panel_chat.removeChildren(),
            (this.chatMsgTotalHeigh = 0),
            (this.label_private_title.text = t.more.name);
          for (var h = 0, r = i.length; h < r; h++)
            if ("系统消息" != i[h].fname) {
              var c = new ChatLineView(),
                l = i[r - h - 1];
              c.privateChatLineMessage(l),
                this.messageArray.push(c),
                this.panel_chat.addChild(c),
                (c.y = this.chatMsgTotalHeigh),
                (this.chatMsgTotalHeigh += c.height);
            }
          if (
            ((this.panel_chat.vScrollBar.max = this.panel_chat.contentHeight),
            (this.panel_chat.vScrollBar.value = this.panel_chat.vScrollBar.max),
            i.length > 30)
          ) {
            i.shift().removeSelf();
          }
        }
      }),
      (e.prototype.isDuringDate = function (t) {
        var e = new Date(t),
          a = new Date(),
          i = e.getTime() - a.getTime(),
          o = Math.floor(i / 1e3 / 60 / 60 / 24);
        return NaN != o && !(o > 0);
      }),
      (e.prototype.updateMessageViewRender = function () {
        for (var t, e = this.messageArray.length, a = 0; a < e; a++)
          t = this.messageArray[e - a - 1];
        (t.y = this.chatMsgTotalHeigh),
          (this.chatMsgTotalHeigh += t.height),
          this.panel_chat.addChild(t),
          (this.panel_chat.vScrollBar.max = this.chatMsgTotalHeigh),
          (this.panel_chat.vScrollBar.value = this.panel_chat.vScrollBar.max);
      }),
      (e.prototype.onClickSendMessageFn = function (t) {
        if (this.text_chat_message.text.length > 0) {
          this.text_chat_message.text;
          if (void 0 == typeof this.currentMsg) return;
          (this.currentMsg = this.text_chat_message.text),
            WebSocketService.send({
              c: 1023,
              d: { roleid: this.jsonDict.id, msg: this.currentMsg },
            }),
            (this.text_chat_message.text = "");
        }
      }),
      (e.prototype.onChatMsgCancleFn = function () {
        this.close(), (e.chatState = !1);
      }),
      (e.close = function () {
        this.chatMsgDialog &&
          (this.chatMsgDialog.close(), (this.chatMsgDialog = null));
      }),
      (e.prototype.onCloseChatMsgFns = function (t) {
        (e.chatState = !1), e.chatMsgDialog.panel_chat.removeChildren();
      }),
      (e.prototype.onSelectedFaceEmojiAction = function () {
        ChatFaceDialog.showChatFaceView("privateChat");
      }),
      (e.prototype.onGetFaceEmojiType = function (t) {
        var e = t.text;
        console.log(t), (this.text_chat_message.text += e);
      }),
      (e.chatState = !1),
      e
    );
  })(ui.FriendMomentController.PrivateChatDialogUI);
